package com.jsfcompref.solutech.backing;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.application.Application;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;


import com.eCommerce.corecontract.dto.ComposantDTO;
import com.ecommerceWeb.common.JSFUtil;
import com.jsfcompref.solutech.model.ComposantPanier;
import com.jsfcompref.solutech.model.PanierAchatBean;
import com.jsfcompref.solutech.model.PanierAchatLocal;

public class PanierAchat {
	
	@EJB
	private PanierAchatLocal panierAchat;
	
	private UIData data = null;
	


	public String addComposantToPanier(){
		FacesContext ctx = FacesContext.getCurrentInstance();
		Application app = ctx.getApplication();
		ComposantDTO composant = (ComposantDTO)JSFUtil.getManagedObject("GetComposant");
		panierAchat.ajouterComposant(composant);
		return "composant.added";
	}
	
	public String removeComposantFromPanier(){
		FacesContext ctx = FacesContext.getCurrentInstance();
		Application app = ctx.getApplication();
		ComposantDTO composant = (ComposantDTO)JSFUtil.getManagedObject("GetComposant");
		panierAchat.removeComposant(composant);
		return null;
	}
	
	public Double getTotal(){
		return panierAchat.getTotal();
	}
	
	public List<ComposantPanier> getComposantsDuPanier(){
		return panierAchat.getComposantsDuPanier();
	}
	public UIData getData() {
		return data;
	}

	public void setData(UIData data) {
		this.data = data;
	}
}
